package com.chinairi.mall.util;

import com.chinairi.common.utils.ApplicationContextUtil;
import com.chinairi.mall.dao.CiccTableMapper;
import com.chinairi.mall.model.CiccRecord;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * @author 李昌赐
 * @since 2020−11-25
 */
@Component
public class CiccRecordUtil implements Serializable {
    private static final long serialVersionUID = -4394841713475342757L;

    @Autowired
    private CiccTableMapper ciccTableMapper;

    public CiccRecordUtil() {
    }

    public static CiccRecord getCiccRecord(String tableName,String code){
        if (StringUtils.isEmpty(code)){
            return new CiccRecord();
        }
        CiccRecord ciccRecord =  getBean().getCiccRecord(tableName,code);
        if (ciccRecord == null){
            return new CiccRecord();
        }
        return ciccRecord;
    }

    private static CiccTableMapper getBean() {
        return (CiccTableMapper) ApplicationContextUtil.getApplicationContext().getBean(CiccTableMapper.class);
    }
}
